<template>
  <div class="app-container home">
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body>
      <el-form v-if="!isonlyread" ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="公告标题" prop="noticeTitle">
              <el-input v-model="form.noticeTitle" placeholder="请输入公告标题" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="公告类型" prop="noticeType">
              <el-select v-model="form.noticeType" placeholder="请选择公告类型">
                <el-option v-for="dict in dict.type.sys_notice_type" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="状态">
              <el-radio-group v-model="form.status">
                <el-radio v-for="dict in dict.type.sys_notice_status" :key="dict.value" :label="dict.value">{{ dict.label }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="内容">
              <editor v-model="form.noticeContent" :min-height="300" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <template v-if="isonlyread">
        <el-descriptions>
          <el-descriptions-item label="公告标题" :span="24">{{
            form.noticeTitle
          }}</el-descriptions-item>
          <el-descriptions-item label="公告类型"><dict-tag :options="dict.type.sys_notice_type" :value="form.noticeType"></dict-tag></el-descriptions-item>
          <el-descriptions-item label="状态">
            <dict-tag :options="dict.type.sys_notice_status" :value="form.status"></dict-tag>
          </el-descriptions-item>
        </el-descriptions>
        <el-descriptions :min-height="300">
          <el-descriptions-item label="内容">
            <div v-html="form.noticeContent"></div>
          </el-descriptions-item>
        </el-descriptions>
      </template>

      <!-- 底部按钮 -->
      <div v-if="!isonlyread" slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
      <div v-if="isonlyread" slot="footer" class="dialog-footer">
        <el-button @click="cancel">返 回</el-button>
      </div>
    </el-dialog>

    <el-row>
      <el-col :xs="24" :sm="24" :md="12" :lg="24">
        <el-card class="update-log">
          <!-- 通知下拉表单 -->
          <el-collapse accordion v-model="activeName">
            <!-- 表单开始 -->
            <el-collapse-item name="1" title="公告">
              <ol>
                <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
                  <el-form-item label="公告标题" prop="noticeTitle">
                    <el-input v-model="queryParams.noticeTitle" placeholder="请输入公告标题" clearable @keyup.enter.native="handleQuery" />
                  </el-form-item>
                  <el-form-item label="操作人员" prop="createBy">
                    <el-input v-model="queryParams.createBy" placeholder="请输入操作人员" clearable @keyup.enter.native="handleQuery" />
                  </el-form-item>
                  <el-form-item label="类型" prop="noticeType">
                    <el-select v-model="queryParams.noticeType" placeholder="公告类型" clearable>
                      <el-option v-for="dict in dict.type.sys_notice_type" :key="dict.value" :label="dict.label" :value="dict.value" />
                    </el-select>
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                  </el-form-item>
                </el-form>
                <el-row :gutter="10" class="mb8">
                  <el-col :span="1.5">
                    <!-- <el-button
                      type="primary"
                      plain
                      icon="el-icon-plus"
                      size="mini"
                      @click="handleAdd"
                      >新增</el-button
                    >
                  </el-col>
                  <el-col :span="1.5">
                    <el-button
                      type="success"
                      plain
                      icon="el-icon-edit"
                      size="mini"
                      :disabled="single"
                      @click="handleUpdate"
                      v-hasPermi="['system:notice:edit']"
                      >修改</el-button
                    > -->
                    <!-- </el-col>
                  <el-col :span="1.5">
                    <el-button
                      type="danger"
                      plain
                      icon="el-icon-delete"
                      size="mini"
                      :disabled="multiple"
                      @click="handleDelete"
                      v-hasPermi="['system:notice:remove']"
                      >删除</el-button
                    > -->
                  </el-col>
                  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
                </el-row>

                <el-table :data="noticeList" @selection-change="handleSelectionChange">
                  <!-- <el-table-column type="selection" width="55" align="center" /> -->
                  <el-table-column label="序号" align="center" prop="noticeId" width="100" />
                  <el-table-column label="公告标题" align="center" prop="noticeTitle" :show-overflow-tooltip="true" @click="handlecheck(scope.row)" />
                  <el-table-column label="公告类型" align="center" prop="noticeType" width="100">
                    <template slot-scope="scope">
                      <dict-tag :options="dict.type.sys_notice_type" :value="scope.row.noticeType" />
                    </template>
                  </el-table-column>
                  <el-table-column label="状态" align="center" prop="status" width="100">
                    <template slot-scope="scope">
                      <dict-tag :options="dict.type.sys_notice_status" :value="scope.row.status" />
                    </template>
                  </el-table-column>
                  <el-table-column label="创建者" align="center" prop="createBy" width="100" />
                  <el-table-column label="创建时间" align="center" prop="createTime" width="100">
                    <template slot-scope="scope">
                      <span>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
                    </template>
                  </el-table-column>
                  <!-- 操作选项 -->
                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                      <el-button size="mini" type="text" icon="el-icon-zoom-in" @click="handlecheck(scope.row)" v-hasPermi="['system:notice:edit']">查看通知</el-button>
                      <!-- <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-edit"
                        @click="handleUpdate(scope.row)"
                        v-hasPermi="['system:notice:edit']"
                        >修改</el-button
                      >
                      <el-button
                        size="mini"
                        type="text"
                        icon="el-icon-delete"
                        @click="handleDelete(scope.row)"
                        v-hasPermi="['system:notice:remove']"
                        >删除</el-button
                      > -->
                    </template>
                  </el-table-column>
                </el-table>
                <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
              </ol>
            </el-collapse-item>
            <!-- 表单结束 -->
            <!-- 第二个下拉页面 -->
            <el-collapse-item title="待办事项卡" name="2" class="transfer">
              <!-- 三个卡片中的一个 -->
              <el-col :span="8">
                <el-card class="box-card-cardholders">
                  <el-row style="display: flex; align-items: center">
                    <el-col :span="6"><h3>待处理</h3></el-col>
                    <el-col :span="6"
                      ><el-button @click="addopenpage(item)">添加待办事项</el-button>
                    </el-col>
                  </el-row>
                  <!-- 循环放出leftdata里的数据 -->
                  <el-col>
                    <!--  -->
                    <el-card v-for="item in leftData" :key="item.id" shadow="hover">
                      <el-row>
                        <el-col :span="10"
                          ><h1>{{ item.label }}</h1></el-col
                        >
                        <el-col :span="10" :offset="4"
                          ><h1>{{ item.manager }}</h1></el-col
                        >
                        <el-col>
                          <div class="box-card-cardholder">{{ item.contents }}</div>
                        </el-col>
                        <el-col style="display: flex; align-items: center">
                          
                          <el-button @click="moveToMiddle(item)">受理</el-button>
                          <el-button @click="moveToRight(item)">结束</el-button>
                        </el-col>
                        <el-col> </el-col>
                      </el-row>
                    </el-card>
                    <!--  -->
                  </el-col>
                  <!--  -->
                </el-card>
              </el-col>
              <!--  -->
              <el-col :span="8">
                <el-card class="box-card-cardholders">
                  <h3>处理中</h3>
                  <el-col>
                    <el-card v-for="item in middleData" :key="item.id" shadow="hover">
                      <el-row>
                        <el-col :span="10"
                          ><h1>{{ item.label }}</h1></el-col
                        >
                        <el-col :span="10" :offset="4"
                          ><h1>{{ item.manager }}</h1></el-col
                        >
                        <el-col>
                          <div class="box-card-cardholder">{{ item.contents }}</div>
                        </el-col>
                        <el-col style="display: flex; align-items: center">
                          <el-button @click="moveToLeft(item)">暂时搁置</el-button>
                          <el-button @click="moveToRight(item)">结束</el-button>
                        </el-col>
                      </el-row>
                    </el-card>
                  </el-col>
                </el-card>
              </el-col>
              <el-col :span="8">
                <el-card class="box-card-cardholders">
                  <h3>处理结束</h3>
                  <el-col>
                    <el-card v-for="item in rightData" :key="item.id" shadow="hover">
                      <el-row>
                        <el-col :span="10"
                          ><h1>{{ item.label }}</h1></el-col
                        >
                        <el-col :span="10" :offset="4"
                          ><h1>{{ item.manager }}</h1></el-col
                        >
                        <el-col>
                          <div class="box-card-cardholder">{{ item.contents }}</div>
                        </el-col>
                        <el-col style="display: flex; align-items: center">
                          <el-button @click="moveToLeft(item)">暂时搁置</el-button>
                          <el-button @click="moveToMiddle(item)">重新受理</el-button>
                          <el-popconfirm
                            confirm-button-text="确定"
                            @confirm="moveToOver(item)"
                            title="你确定要关闭处理通道吗？"
                          >
                            <el-button slot="reference">关闭处理</el-button>
                          </el-popconfirm>
                          <el-popconfirm
                            confirm-button-text="确定"
                            @confirm="moveToRedo(item)"
                            title="你确定要重启吗？"
                          >
                            <el-button slot="reference">重启</el-button>
                          </el-popconfirm>
                        </el-col>
                        <el-col> </el-col>
                      </el-row>
                    </el-card>
                  </el-col>
                </el-card>
              </el-col>
            </el-collapse-item>
          </el-collapse>
          <!-- 折叠菜单结束 -->
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { listNotice, getNotice, delNotice, addNotice, updateNotice } from '@/api/system/notice';
export default {
  name: 'Index',
  dicts: ['sys_notice_status', 'sys_notice_type'],

  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 公告表格数据
      noticeList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      //查看界面
      isonlyread: false,

      activeName: '1',

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        noticeTitle: undefined,
        createBy: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        noticeTitle: [{ required: true, message: '公告标题不能为空', trigger: 'blur' }],
        noticeType: [{ required: true, message: '公告类型不能为空', trigger: 'change' }]
      },
      //卡片校验
      noterules: {
        noteaddname: [{ required: true, message: "事件名称不能为空", trigger: "blur" }],
        notemanager: [{ required: true, message: "事件负责人不能为空", trigger: "blur" }],
        notedesc: [{ required: true, message: "事件内容不能为空", trigger: "blur" }],
      },
      // 版本号
      version: "3.8.6",
      //通知

      //卡片的item
      // item: "",

      //

      //
      leftData: [
        {
          id: 1,
          label: "Item 1",
          contents: "item1",
          manager: "admin",
          timeleft: undefined,
          isOver: false,
        },
        {
          id: 2,
          label: "Item 2",
          contents: "item2",
          manager: "admin",
          timeleft: undefined,
          isOver: false,
        },
        {
          id: 3,
          label: "Item 3",
          contents: "item3",
          manager: "admin",
          timeleft: undefined,
          isOver: false,
        },
      ],
      middleData: [
        // 中间列表的数据
        // { id: 4, label: "Item 4", contents: "item4", isOver: false },
      ],
      rightData: [
        // 右侧列表的数据
        // { id: 5, label: "Item 5", contents: "item5", isOver: false },
      ],
    };
  },
  methods: {
    goTarget(href) {
      window.open(href, '_blank');
    }
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询公告列表 */
    getList() {
      this.loading = true;
      listNotice(this.queryParams).then(response => {
        this.noticeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        noticeId: undefined,
        noticeTitle: undefined,
        noticeType: undefined,
        noticeContent: undefined,
        status: '0'
      };
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.noticeId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.isonlyread = false;
      this.open = true;
      this.title = '添加公告';
    },
    /**查看 */
    handlecheck(row) {
      this.reset();
      const noticeId = row.noticeId || this.ids;
      getNotice(noticeId).then(response => {
        this.form = response.data;
        this.isonlyread = true;
        this.open = true;
        this.title = '查看通知';
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const noticeId = row.noticeId || this.ids;
      getNotice(noticeId).then(response => {
        this.form = response.data;
        this.isonlyread = false;
        this.open = true;
        this.title = '修改公告';
      });
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.noticeId != undefined) {
            updateNotice(this.form).then(response => {
              this.$modal.msgSuccess('修改成功');
              this.open = false;
              this.getList();
            });
          } else {
            addNotice(this.form).then(response => {
              this.$modal.msgSuccess('新增成功');
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },

       /** 新增待办事项操作 */
       addopenpage() {
      this.reset();
      this.addopen = true;
      this.title = "待办事项";
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const noticeIds = row.noticeId || this.ids;
      this.$modal
        .confirm('是否确认删除公告编号为"' + noticeIds + '"的数据项？')
        .then(function () {
          return delNotice(noticeIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess('删除成功');
        })
        .catch(() => {});
    },
/** 添加待办事项操作 */
addnotecomm() {
      // console.log("first",this.form.noteaddname,this.form.notedesc,this.form.notemanager);
      if (
        this.form.noteaddname !== undefined &&
        this.form.notedesc !== undefined &&
        this.form.notemanager !== undefined
      ) {
        //获取input中的数据
        const noteName = this.form.noteaddname;
        const notedesc = this.form.notedesc;
        const notemanager = this.form.notemanager;

        //测试id
        // console.log(this.leftData.length + this.rightData.length + this.middleData.leftData + 1);
        // console.log(this.leftData.length, this.middleData.length, this.rightData.length);

        const newItem = {
          id: this.leftData.length + this.middleData.length + this.rightData.length + 1,
          label: noteName,
          manager: notemanager,
          contents: notedesc,
          isOver: false,
        };
        this.leftData.push(newItem);
        // console.log("before",this.form.noteaddname,this.form.notedesc,this.form.notemanager);
        this.reset();
        // console.log("after",this.form.noteaddname,this.form.notedesc,this.form.notemanager);
        this.addopen = false;
        //成功弹窗提示
        this.$message({
          message: "成功添加",
          type: "success",
        });
      } else {
        this.$message({
          message: "格式错误,请检查输入格式",
          type: "error",
        });
      }
    },
    // /** 修改按钮操作 */
    // handleUpdate(row) {
    //   this.reset();
    //   const noticeId = row.noticeId || this.ids;
    //   getNotice(noticeId).then((response) => {
    //     this.form = response.data;
    //     this.isonlyread = false;
    //     this.open = true;
    //     this.title = "修改公告";
    //   });
    // },
    // /** 提交按钮 */
    // submitForm: function () {
    //   this.$refs["form"].validate((valid) => {
    //     if (valid) {
    //       if (this.form.noticeId != undefined) {
    //         updateNotice(this.form).then((response) => {
    //           this.$modal.msgSuccess("修改成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       } else {
    //         addNotice(this.form).then((response) => {
    //           this.$modal.msgSuccess("新增成功");
    //           this.open = false;
    //           this.getList();
    //         });
    //       }
    //     }
    //   });
    // },
    // /** 删除按钮操作 */
    // handleDelete(row) {
    //   const noticeIds = row.noticeId || this.ids;
    //   this.$modal
    //     .confirm('是否确认删除公告编号为"' + noticeIds + '"的数据项？')
    //     .then(function () {
    //       return delNotice(noticeIds);
    //     })
    //     .then(() => {
    //       this.getList();
    //       this.$modal.msgSuccess("删除成功");
    //     })
    //     .catch(() => {});
    // },

    //第二页按钮操作
    //toend
    moveToRight(item) {
      const index = this.leftData.findIndex((i) => i.id === item.id);
      if (index >= 0) {
        this.rightData.push(this.leftData[index]);
        this.leftData.splice(index, 1);
      } else {
        const middleIndex = this.middleData.findIndex((i) => i.id === item.id);
        if (middleIndex >= 0) {
          this.rightData.push(this.middleData[middleIndex]);
          this.middleData.splice(middleIndex, 1);
        }
      }
    },
    //tostart
    moveToLeft(item) {
      if (!item.isOver) {
        const index = this.rightData.findIndex((i) => i.id === item.id);
        if (index >= 0) {
          this.leftData.push(this.rightData[index]);
          this.rightData.splice(index, 1);
        } else {
          const middleIndex = this.middleData.findIndex((i) => i.id === item.id);
          if (middleIndex >= 0) {
            this.leftData.push(this.middleData[middleIndex]);
            this.middleData.splice(middleIndex, 1);
          }
        }
      } else {
        this.$message({
          message: "通道已关闭，不能操作",
          type: "warning",
        });
      }
    },
    //tomiddle
    moveToMiddle(item) {
      if (!item.isOver) {
        const index = this.leftData.findIndex((i) => i.id === item.id);
        if (index >= 0) {
          this.middleData.push(this.leftData[index]);
          this.leftData.splice(index, 1);
        } else {
          const index = this.rightData.findIndex((i) => i.id === item.id);
          if (index >= 0) {
            this.middleData.push(this.rightData[index]);
            this.rightData.splice(index, 1);
          }
        }
      } else {
        // console.log("this is error~~~~~");
        this.$message({
          message: "通道已关闭，不能操作",
          type: "warning",
        });
      }
    },
    //toover
    moveToOver(item) {
      if (item.isOver == true) {
        this.$message({
          message: "任务已结束",
          type: "warning",
        });
      } else {
        const index = this.rightData.findIndex((i) => i.id === item.id);
        if (index >= 0) {
          this.rightData[index].isOver = true;
        } else {
          const middleIndex = this.middleData.findIndex((i) => i.id === item.id);

          if (middleIndex >= 0) {
            this.middleData[middleIndex].isOver = true;
          }
        }
        this.$message({
          message: "成功结束任务",
          type: "success",
        });
      }
    },
    //redo
    moveToRedo(item) {
      if (item.isOver == false) {
        this.$message({
          message: "任务正在处理中",
          type: "warning",
        });
      } else {
        const index = this.rightData.findIndex((i) => i.id === item.id);
        if (index >= 0) {
          this.rightData[index].isOver = false;
        } else {
          const middleIndex = this.middleData.findIndex((i) => i.id === item.id);

          if (middleIndex >= 0) {
            this.middleData[middleIndex].isOver = false;
          }
        }
        this.moveToLeft(item);
        this.$message({
          message: "成功重启任务",
          type: "success",
        });
      }
    },
  },
};
</script>

<style>
/* .el-collapse-item__header {
  font-size: 30px;
  color: #f56c6c;
} */
.el-collapse-item__arrow {
  margin-right: 5px;
  font-size: 18px;
}
.el-collapse-item__header {
  background: #f0f4fb;
  /* border: 1px solid #DCDCDC; */
  border-left: 2px solid #4b8fff;
  padding-left: 20px;
  font-size: 30px;
  font-weight: lighter;
  font-family: Arial, Helvetica, sans-serif;
}

img {
  width: 20vw;
  height: 20vw;
}

.box-card-cardholders {
  min-height: 600px;
  padding-bottom: 30px;
}
</style>